//
//  tabbarController.m
//  实战项目  爱限免 App
//
//  Created by xiaxiangquan on 15/7/6.
//  Copyright (c) 2015年 xiaxiangquan. All rights reserved.
//

#import "tabbarController.h"
#import "HomeViewController.h"
#import "LiveBroadcastController.h"
#import "AttentionViewController.h"
#import "MyCenterViewController.h"

@interface tabbarController ()
{
    NSMutableArray * vcArrs;
}

@end

@implementation tabbarController


+ (instancetype)getInstance {
    static tabbarController *_shared = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _shared = [tabbarController new];
    });
    return _shared;
}

-(id)init
{
    if (self = [super init])
    {
        //设置tabbar 背景图片
        UIView * view = [[UIView alloc]initWithFrame:CGRectMake(0,0,self.view.bounds.size.width,49)];
        UIImage * image = [UIImage imageNamed:@"tabbar_bg"];
        UIColor * color = [[UIColor alloc]initWithPatternImage:image];
        [view setBackgroundColor:color];
        [[self tabBar]insertSubview:view atIndex:0];
        self.tabBar.tintColor = [UIColor orangeColor];
        
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    //初始化所有子控制器
     vcArrs = [NSMutableArray new];
    [self setAllChildViewController];
    
}

-(void)setAllChildViewController
{
    
    MyCenterViewController * four = [[MyCenterViewController alloc]init];
    [self setChildViewController:four title:@"🤓新闻" imageName:@"我的@3x" selectedImageName:@"我的1@3x"];
    
    AttentionViewController * three = [[AttentionViewController alloc]init];
    //    threeTableViewController * three = [[threeTableViewController alloc]init];
    [self setChildViewController:three title:@"⭐️综艺" imageName:@"消息@2x" selectedImageName:@"消息1@2x"];
    
     LiveBroadcastController * two = [[LiveBroadcastController alloc]init];
//    twoTableViewController * two = [[twoTableViewController alloc]init];
    [self setChildViewController:two title:@"🈲娱乐" imageName:@"就诊@2x" selectedImageName:@"就诊1@2x"];

    HomeViewController * one = [[HomeViewController alloc]init];
    //    one.tabBarItem.badgeValue = @"1";右上角提醒数字
    [self setChildViewController:one title:@"🎙直播" imageName:@"首页1@2x" selectedImageName:@"首页@2x"];

    

}

//设置tabbar 的标题和图片
-(void)setChildViewController:(UIViewController *)comtroller title:(NSString *)title imageName:(NSString *)imageName selectedImageName:(NSString*)selectedImageName
{
    comtroller.title = title;
    
    if (imageName)
    {
        comtroller.tabBarItem.image = [UIImage imageNamed:imageName];
    }
    comtroller.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImageName]imageWithRenderingMode:
                                           UIImageRenderingModeAlwaysOriginal];
    
    
    [self addChildViewController:comtroller];
  
}
-(void)pushViewController:(UIViewController *)controller
{
    [self.navigationController pushViewController:controller animated:YES];
}

-(void)presentViewController:(UIViewController *)controller
{
    [self presentViewController:controller animated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
